|
1
|
|
|
GLSR.colorControls = function() |
|
|
|
|
|
|
2
|
|
|
{ |
|
3
|
|
|
if( typeof x.wp !== 'object' || typeof x.wp.wpColorPicker !== 'function' )return; |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
x( document ).find( 'input[type="text"].color-picker-hex' ).each( function() { |
|
6
|
|
|
var t = x( this ); |
|
7
|
|
|
var options = t.data( 'colorpicker' ) || {}; |
|
8
|
|
|
t.wpColorPicker( options ); |
|
9
|
|
|
}); |
|
10
|
|
|
}; |
|
11
|
|
|
|
|
12
|
|
|
GLSR.dismissNotices = function() |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
x( '.notice.is-dismissible' ).each( function() { |
|
15
|
|
|
var notice = x( this ); |
|
16
|
|
|
notice.fadeTo( 100, 0, function() { |
|
17
|
|
|
notice.slideUp( 100, function() { |
|
18
|
|
|
notice.remove(); |
|
19
|
|
|
}); |
|
20
|
|
|
}); |
|
21
|
|
|
}); |
|
22
|
|
|
}; |
|
23
|
|
|
|
|
24
|
|
|
GLSR.getURLParameter = function( name ) |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
return decodeURIComponent( |
|
27
|
|
|
(new RegExp( '[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)' ).exec( location.search ) || [null, ''])[1].replace( /\+/g, '%20' ) |
|
28
|
|
|
) || null; |
|
29
|
|
|
}; |
|
30
|
|
|
|
|
31
|
|
|
GLSR.insertNotices = function( notices ) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
notices = notices || false; |
|
34
|
|
|
|
|
35
|
|
|
if( !notices )return; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
if( !x( '#glsr-notices' ).length ) { |
|
38
|
|
|
x( '#message.notice' ).remove(); |
|
39
|
|
|
x( 'form#post' ).before( '<div id="glsr-notices" />' ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
x( '#glsr-notices' ).html( notices ); |
|
43
|
|
|
|
|
44
|
|
|
x( document ).trigger( 'wp-updates-notice-added' ); |
|
45
|
|
|
}; |
|
46
|
|
|
|
|
47
|
|
|
GLSR.isUndefined = function( value ) |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
var is_undefined = void(0); |
|
|
|
|
|
|
50
|
|
|
return value === is_undefined; |
|
51
|
|
|
}; |
|
52
|
|
|
|
|
53
|
|
|
GLSR.normalizeValue = function( value ) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
if(['true','on','1'].indexOf( value ) > -1 ) { |
|
56
|
|
|
return true; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if(['false','off','0'].indexOf( value ) > -1 ) { |
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return value; |
|
64
|
|
|
}; |
|
65
|
|
|
|
|
66
|
|
|
GLSR.normalizeValues = function( array ) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
return array.map( GLSR.normalizeValue ); |
|
|
|
|
|
|
69
|
|
|
}; |
|
70
|
|
|
|
|
71
|
|
|
GLSR.onChangeStatus = function( ev ) |
|
72
|
|
|
{ |
|
73
|
|
|
var post_id = this.href.match(/post=([0-9]+)/)[1]; |
|
74
|
|
|
var status = this.href.match(/action=([a-z]+)/)[1]; |
|
75
|
|
|
|
|
76
|
|
|
if( GLSR.isUndefined( status ) || GLSR.isUndefined( post_id ))return; |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
var request = { |
|
79
|
|
|
action: 'change-review-status', |
|
80
|
|
|
status : status, |
|
81
|
|
|
post_id: post_id, |
|
82
|
|
|
}; |
|
83
|
|
|
|
|
84
|
|
|
GLSR.postAjax( ev, request, function( response ) |
|
85
|
|
|
{ |
|
86
|
|
|
var el = x( ev.target ); |
|
87
|
|
|
|
|
88
|
|
|
el.closest( 'tr' ).removeClass( 'status-pending status-publish' ).addClass( response.class ); |
|
89
|
|
|
el.closest( 'td.column-title' ).find( 'strong' ).html( response.link ); |
|
90
|
|
|
}); |
|
91
|
|
|
}; |
|
92
|
|
|
|
|
93
|
|
|
GLSR.onClearLog = function( ev ) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
var request = { |
|
96
|
|
|
action: 'clear-log', |
|
97
|
|
|
}; |
|
98
|
|
|
GLSR.postAjax( ev, request, function( response ) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
GLSR.insertNotices( response.notices ); |
|
|
|
|
|
|
101
|
|
|
x( '#log-file' ).val( response.logger ); |
|
102
|
|
|
}); |
|
103
|
|
|
}; |
|
104
|
|
|
|
|
105
|
|
|
GLSR.onFieldChange = function() |
|
106
|
|
|
{ |
|
107
|
|
|
var depends = x( this ).closest( 'form' ).find( '[data-depends]' ); |
|
108
|
|
|
|
|
109
|
|
|
if( !depends.length )return; |
|
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
var name = this.getAttribute( 'name' ); |
|
112
|
|
|
var type = this.getAttribute( 'type' ); |
|
113
|
|
|
|
|
114
|
|
|
for( var i = 0; i < depends.length; i++ ) { |
|
115
|
|
|
|
|
116
|
|
|
try { |
|
117
|
|
|
var data = JSON.parse( depends[i].getAttribute( 'data-depends' ) ); |
|
118
|
|
|
var bool; |
|
119
|
|
|
|
|
120
|
|
|
if( data.name !== name )continue; |
|
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
if( 'checkbox' === type ) { |
|
123
|
|
|
bool = !!this.checked; |
|
124
|
|
|
} |
|
125
|
|
|
else if( x.isArray( data.value ) ) { |
|
|
|
|
|
|
126
|
|
|
bool = x.inArray( GLSR.normalizeValue( this.value ), GLSR.normalizeValues( data.value ) ) !== -1; |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
else { |
|
129
|
|
|
bool = GLSR.normalizeValue( data.value ) === GLSR.normalizeValue( this.value ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
GLSR.toggleHiddenField( depends[i], bool ); |
|
133
|
|
|
} |
|
134
|
|
|
catch( e ) { |
|
135
|
|
|
console.error( 'JSON Error: ' + depends[i] ); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
}; |
|
139
|
|
|
|
|
140
|
|
|
GLSR.pointers = function( pointer ) |
|
141
|
|
|
{ |
|
142
|
|
|
x( pointer.target ).pointer({ |
|
143
|
|
|
content: pointer.options.content, |
|
144
|
|
|
position: pointer.options.position, |
|
145
|
|
|
close: function() { |
|
146
|
|
|
x.post( ajaxurl, { |
|
|
|
|
|
|
147
|
|
|
pointer: pointer.id, |
|
148
|
|
|
action: 'dismiss-wp-pointer', |
|
149
|
|
|
}); |
|
150
|
|
|
}, |
|
151
|
|
|
}) |
|
152
|
|
|
.pointer( 'open' ) |
|
153
|
|
|
.pointer( 'sendToTop' ); |
|
154
|
|
|
|
|
155
|
|
|
x( document ).on( 'wp-window-resized', function() { |
|
156
|
|
|
x( pointer.target ).pointer( 'reposition' ); |
|
157
|
|
|
}); |
|
158
|
|
|
}; |
|
159
|
|
|
|
|
160
|
|
|
GLSR.postAjax = function( ev, request, callback ) |
|
|
|
|
|
|
161
|
|
|
{ |
|
162
|
|
|
ev.preventDefault(); |
|
163
|
|
|
var el = x( ev.target ); |
|
164
|
|
|
if( el.is( ':disabled' ))return; |
|
|
|
|
|
|
165
|
|
|
request.nonce = request.nonce || el.closest( 'form' ).find( '#_wpnonce' ).val(); |
|
166
|
|
|
var data = { |
|
167
|
|
|
action: site_reviews.action, |
|
|
|
|
|
|
168
|
|
|
request: request, |
|
169
|
|
|
}; |
|
170
|
|
|
el.prop( 'disabled', true ); |
|
171
|
|
|
x.post( site_reviews.ajaxurl, data, function( response ) { |
|
|
|
|
|
|
172
|
|
|
if( typeof callback === 'function' ) { |
|
173
|
|
|
callback( response ); |
|
174
|
|
|
} |
|
175
|
|
|
el.prop( 'disabled', false ); |
|
176
|
|
|
}); |
|
177
|
|
|
}; |
|
178
|
|
|
|
|
179
|
|
|
GLSR.textareaResize = function( el ) |
|
|
|
|
|
|
180
|
|
|
{ |
|
181
|
|
|
var minHeight = 320; |
|
182
|
|
|
var textarea = el[0]; |
|
183
|
|
|
|
|
184
|
|
|
textarea.style.height = 'auto'; |
|
185
|
|
|
|
|
186
|
|
|
textarea.style.height = textarea.scrollHeight > minHeight ? |
|
187
|
|
|
textarea.scrollHeight + 'px' : |
|
188
|
|
|
minHeight + 'px'; |
|
189
|
|
|
}; |
|
190
|
|
|
|
|
191
|
|
|
GLSR.toggleHiddenField = function( el, bool ) |
|
|
|
|
|
|
192
|
|
|
{ |
|
193
|
|
|
var row = x( el ).closest( '.glsr-field' ); |
|
194
|
|
|
|
|
195
|
|
|
if( !row.length )return; |
|
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
if( bool ) { |
|
198
|
|
|
row.removeClass( 'hidden' ); |
|
199
|
|
|
} |
|
200
|
|
|
else { |
|
201
|
|
|
row.addClass( 'hidden' ); |
|
202
|
|
|
} |
|
203
|
|
|
}; |
|
204
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.